<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="Write an awesome description
		for your new site here. You can edit this line in _config.yml.
		It will appear in your document head meta (for Google search results)
		and in your feed.xml site description.
		">
    <title>下载完赛证书</title>

    <link rel="stylesheet" href="../lib/weui.min.css">
    <link rel="stylesheet" href="../css/jquery-weui.css">
    <link rel="stylesheet" href="../css/demos.css">
    <script src="../lib/jquery-2.1.4.js"></script>
    <script src="../lib/fastclick.js"></script>
    <script src="../js/jquery-weui.js"></script>
    <script src="../js/weui.min.js"></script>
    <script src="../js/layer.js" charset="utf-8"></script>
</head>
<body>
<header class='demos-header'>
    <h2 class="demos-second-title">下载完赛证书</h2>
</header>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <input hidden id="eventBeginTime" value="${eventBeginTime}"/>
        <div class="weui-cell__hd"><label for="event_price_id" class="weui-label">赛事名称</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${eventName}" readonly="" id="event_id"
                   name="event_id">
            <input type="hidden" name="eventId" value="${eventId}"/>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="place" class="weui-label">比赛地址</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${place}" readonly="" id="place"
                   name="event_id">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="guide" class="weui-label">指导方</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${guide}" readonly="" id="guide"
                   name="organizerName">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="organizerName" class="weui-label">主办方</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${organizerName}" readonly="" id="organizerName"
                   name="organizerName">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="host" class="weui-label">承办方</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${host}" readonly="" id="host"
                   name="host">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="executive" class="weui-label">执行方</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" value="${executive1}" readonly="" id="executive"
                   name="executive">
            <input class="weui-input" type="text" value="${executive2}" readonly="" id="executive"
                   name="executive">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="code" class="weui-label">参赛号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" type="text" placeholder="请输入参赛号" id="code" maxlength="100"
                   name="code"/>
        </div>
    </div>

</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="next">下载完赛证书</a>
</div>
</body>
<script>
    $(document).ready(function () {
        $("#code").focus();
        var eventBeginTime = $("#eventBeginTime").val()
        let beginParse = Date.parse(eventBeginTime);

        if (Date.now()<beginParse) {
            alert("功能暂未到开放时间，请完赛后再继续");
            var userAgent = navigator.userAgent;
            if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
                document.addEventListener('WeixinJSBridgeReady', function () {
                    WeixinJSBridge.call('closeWindow');
                }, false)
            } else {
                setTimeout(function () {
                    WeixinJSBridge.invoke("closeWindow", {}, function (e) {
                    })
                }, 100)
            }
            return false;
        }
    });
    $("#next").click(function () {
        var loading ;
        var code = $("#code").val()
        if (code == "") {
            $.toptip('警告,参赛码不能为空', 'warning');
            return false;
        }else{
            loading =  layer.load(1, {
                shade: [0.5,'#fff'],
            });
        }
        $.ajax({
            url: "/participant/race/certificate?eventId=${eventId}&code=" + code,
            method: "post",
            dataType: "json",
            async: false,
            contentType: "application/json",
            success: function (res) {
                if (res.status === 1) {
                    layer.close(loading);
                    let content = '<html lang="en">' +
                            '<head>' +
                            '    <meta charset="UTF-8">' +
                            '    <meta http-equiv="X-UA-Compatible" content="IE=edge">' +
                            '    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">' +
                            '    <meta name="description" content="Write an awesome description' +
                            '          for your new site here. You can edit this line in _config.yml.' +
                            '          It will appear in your document head meta (for Google search results)' +
                            '          and in your feed.xml site description.' +
                            '          ">' +
                            '</head>'+
                            '<body>'+
                            '<img src="'+res.data+'" width=100% height:100%>'+
                            ' </body>'

                    layer.open({
                        type: 1 //Page层类型
                        ,area: ['400px', '300px']
                        ,title:"完赛证书"
                        ,shade: 0.6 //遮罩透明度
                        ,maxmin: true //允许全屏最小化
                        ,anim: 1 //0-6的动画形式，-1不开启
                        ,content: content
                    });
                } else {
                    layer.close(loading);
                    alert(res.msg)
                    return false;
                }
            }
        })
        layer.close(loading);
    })

</script>
</html>